package org.example;

import com.alibaba.fastjson.JSON;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    private static final Logger logger = LogManager.getLogger("HelloWorld");

    @GetMapping("test")
    public String test() {
        logger.info("Hello, World!222\n");

        String jsonString = "{\"name\":\"John\", \"age\":30}";

        // 将JSON字符串转换成Java对象（将 JSON 字符串反序列化成 Person 对象）
        Person person = JSON.parseObject(jsonString, Person.class);
        logger.info("Name: " + person.getName() + ",Age: " + person.getAge());

        // 将Java对象转换成JSON字符串（将 Person 对象序列化成 JSON 字符串）
        person.setAge(33);
        String jsonResult = JSON.toJSONString(person);
        logger.info("JSON String: " + jsonResult);

        return jsonResult;
    }
}